package com.itisyue.fun.utils;//package com.itisyue.fun.utils;
//
//import com.alibaba.fastjson.JSONObject;
//import com.fasterxml.jackson.databind.JsonNode;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.dataformat.xml.XmlMapper;
//
///**
//  <dependency>
//      <groupId>com.fasterxml.jackson.dataformat</groupId>
//      <artifactId>jackson-dataformat-xml</artifactId>
//      <version>2.13.0</version> <!-- 请使用最新的版本 -->
//  </dependency>
//  <dependency>
//      <groupId>com.fasterxml.jackson.core</groupId>
//      <artifactId>jackson-core</artifactId>
//      <version>2.13.0</version> <!-- 请使用最新的版本 -->
//  </dependency>
//  <dependency>
//      <groupId>com.fasterxml.jackson.core</groupId>
//      <artifactId>jackson-databind</artifactId>
//      <version>2.13.0</version> <!-- 请使用最新的版本 -->
//  </dependency>
// */
//public class XmlUtil {
//    public static void main(String[] args) {
//        String xml = "<res><head><res-code>0000</res-code><res-message>操作成功</res-message><res-time>23</res-time><req-seq-no>51100202403051925261427155475793</req-seq-no><res-seq-no>20240305192526181753318221319730</res-seq-no></head><sdk-res><cryptType>0</cryptType><sdk-param><action>3</action><cryptType>0</cryptType><definitionAsk>15</definitionAsk><eyeDegree>15</eyeDegree><headHigh>10</headHigh><headLeft>-12</headLeft><headLow>-5</headLow><headRight>15</headRight><imgCompress>85</imgCompress><imgHeight>480</imgHeight><imgWidth>640</imgWidth><interfaceType>2</interfaceType><isActived>2</isActived><isAudio>1</isAudio><mouthDegree>25</mouthDegree><pupilDistMax>130</pupilDistMax><pupilDistMin>70</pupilDistMin><timeOut>45</timeOut><version>v1.0.7</version><cryptAlgorithm>1</cryptAlgorithm></sdk-param></sdk-res></res>";
//        JSONObject jsonObject = xmlToJson(xml);
//        if(jsonObject!=null && jsonObject.containsKey("head")){
//            if("0000".equals(jsonObject.getJSONObject("head").getString("res-code"))){
//                JSONObject sdkParam = jsonObject.getJSONObject("sdk-res").getJSONObject("sdk-param");
//                System.out.println(sdkParam);
//                String sdkParamXml = jsonToXml(sdkParam.toJSONString());
//                System.out.println(sdkParamXml);
//            }
//        }
//    }
//    public static JSONObject xmlToJson(String xml){
//        try {
//            // 创建XML Mapper
//            XmlMapper xmlMapper = new XmlMapper();
//            // 从XML字符串读取数据并解析为JsonNode
//            //String xml = "<res><head><res-code>0000</res-code><res-message>操作成功</res-message><res-time>23</res-time><req-seq-no>51100202403051925261427155475793</req-seq-no><res-seq-no>20240305192526181753318221319730</res-seq-no></head><sdk-res><cryptType>0</cryptType><sdk-param><action>3</action><cryptType>0</cryptType><definitionAsk>15</definitionAsk><eyeDegree>15</eyeDegree><headHigh>10</headHigh><headLeft>-12</headLeft><headLow>-5</headLow><headRight>15</headRight><imgCompress>85</imgCompress><imgHeight>480</imgHeight><imgWidth>640</imgWidth><interfaceType>2</interfaceType><isActived>2</isActived><isAudio>1</isAudio><mouthDegree>25</mouthDegree><pupilDistMax>130</pupilDistMax><pupilDistMin>70</pupilDistMin><timeOut>45</timeOut><version>v1.0.7</version><cryptAlgorithm>1</cryptAlgorithm></sdk-param></sdk-res></res>";
//
//            JsonNode jsonNode = xmlMapper.readTree(xml);
//            // 创建JSON Mapper
//            ObjectMapper jsonMapper = new ObjectMapper();
//            // 将JsonNode转换为JSON字符串
//            String json = jsonMapper.writeValueAsString(jsonNode);
//            //System.out.println("JSON格式数据:");
//            //System.out.println(json);
//
//            JSONObject jsonObject = JSONObject.parseObject(json);
//            return jsonObject;
//            //System.out.println(jsonObject.getJSONObject("head"));
//            //JSONObject sdkParam = jsonObject.getJSONObject("sdk-res").getJSONObject("sdk-param");
//
//            //System.out.println(sdkParam);
//
//            //jsonToXml(sdkParam.toJSONString());
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return new JSONObject();
//    }
//
//    public static String jsonToXml(String json) {
//        try {
//            // 创建JSON Mapper
//            ObjectMapper jsonMapper = new ObjectMapper();
//            // 从JSON字符串读取数据并解析为JsonNode
//            //String json = "{\"root\":{\"name\":\"John\",\"age\":30}}";
//            JsonNode jsonNode = jsonMapper.readTree(json);
//            // 创建XML Mapper
//            XmlMapper xmlMapper = new XmlMapper();
//            // 将JsonNode转换为XML字符串
//            String xml = xmlMapper.writeValueAsString(jsonNode);
//            //System.out.println("XML格式数据:");
//            //System.out.println(xml);
//            return xml;
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return "";
//    }
//}